package com.dm.cloud.images.service.impl;

import cn.hutool.core.util.StrUtil;
import com.dm.cloud.tkmybatis.service.BaseMapper;
import com.dm.cloud.images.mapper.ImagesAppTaskContainerMapper;
import com.dm.cloud.images.service.ImagesAppTaskContainerService;
import com.dm.cloud.images.common.po.ImagesAppTaskContainer;
import com.dm.cloud.core.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
   * @author hcx
   * @type ImagesAppTaskContainerServiceImpl.java
   * @desc ImagesAppTaskContainer serviceImpl
   */
@Service

@Transactional

public class ImagesAppTaskContainerServiceImpl implements ImagesAppTaskContainerService {


    @Autowired
    private ImagesAppTaskContainerMapper imagesAppTaskContainerMapper;


    @Override
    public BaseMapper getMapper() {
        return imagesAppTaskContainerMapper;
    }
    public void processBeforeOperation(ImagesAppTaskContainer entity, BaseOperationEnum operationEnum) throws CustomException {
    }

    public void processAfterOperation(ImagesAppTaskContainer entity, BaseOperationEnum operationEnum) throws CustomException {
    }


    @Override
    public int updateStatus(String id, int status) {
        return imagesAppTaskContainerMapper.updateStatusById(id,status);
    }

    @Override
    public int updateResoult(String id, int result) {
        return imagesAppTaskContainerMapper.updateResoultById(id,result);
    }

    @Override
    public int updateStatus(String taskId, String nodeId, String containerId, int status) {

        return imagesAppTaskContainerMapper.updateStatusByContainer(taskId,nodeId,containerId,status);
    }

    @Override
    public int updateResoult(String taskId, String nodeId, String containerId, int result) {
        return imagesAppTaskContainerMapper.updateResoultByContainer(taskId, nodeId, containerId, result);
    }

    @Override
    public int updateResoult(String taskId, String nodeId, String containerId, int result,String errStr) {
        if(StrUtil.isEmpty(errStr)){
            return imagesAppTaskContainerMapper.updateResoultByContainer(taskId, nodeId, containerId, result);
        }else{
            return imagesAppTaskContainerMapper.updateResultAndErrStrByContainer(taskId, nodeId, containerId, result,errStr);
        }
    }
}
